package com.zhuge_new.Activity;

import android.content.Intent;
import android.mtp.MtpConstants;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.zhuge_new.Adapter.CardListAdapter;
import com.zhuge_new.Base.BaseActivity;
import com.zhuge_new.R;
import com.zhuge_new.bean.CardListBean;
import com.zhuge_new.http.StringDialogCallback;
import com.zhuge_new.share.BaseHttp;
import com.zhuge_new.untils.DataParse;
import com.zhuge_new.untils.PreferencesUtils;

/**
 * Created by Administrator on 2018/10/19.
 */

public class CreditManageActivity extends BaseActivity {
    private RecyclerView credit_manage_list;
    private View head;
    private View footer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_creditmanage);
        head = View.inflate(baseContext, R.layout.header_home, null);
        footer = View.inflate(baseContext, R.layout.footer_home, null);
        init_title();
        getData();
    }

    @Override
    public void init_title() {
        super.init_title();
        credit_manage_list = findViewById(R.id.credit_manage_list);
        credit_manage_list.setLayoutManager(new LinearLayoutManager(this));

    }

    public void getData() {
        OkGo.<String>post(BaseHttp.creditcard_datas)
                .tag(this)
                .headers("token", PreferencesUtils.getString(baseContext, "token"))
                .execute(new StringDialogCallback(baseContext) {
                    @Override
                    public void onSuccessResponse(Response<String> response, String msg, String msgCode) {
                        final CardListBean cardListBean = (CardListBean) new DataParse().getBean(response.body(), CardListBean.class, 1);
                        final CardListAdapter cardListAdapter = new CardListAdapter(baseContext, cardListBean.getCreditcards());
                        cardListAdapter.addHeaderView(head);
                        cardListAdapter.addFooterView(footer);
                        credit_manage_list.setAdapter(cardListAdapter);
                        cardListAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                            @Override
                            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                                switch (view.getId()) {
                                    case R.id.tv_pepay:
                                        Intent intent = new Intent(CreditManageActivity.this, RnSuccessActivity.class);
                                        intent.putExtra("bank", cardListBean.getCreditcards().get(position).getBank());
                                        intent.putExtra("name", cardListBean.getCreditcards().get(position).getName());
                                        intent.putExtra("logoUrl", cardListBean.getCreditcards().get(position).getLogoUrl());
                                        intent.putExtra("creditcard", cardListBean.getCreditcards().get(position).getCreditcard());
                                        intent.putExtra("creditcardId", cardListBean.getCreditcards().get(position).getCreditcardId());
                                        intent.putExtra("billDay", cardListBean.getCreditcards().get(position).getBillDay());
                                        intent.putExtra("repaymentDay", cardListBean.getCreditcards().get(position).getRepaymentDay());
                                        startActivity(intent);
                                        break;
                                    case R.id.home_bill:
                                        Intent intent1 = new Intent(CreditManageActivity.this, CheckActivity.class);
                                        intent1.putExtra("creditcardId", cardListBean.getCreditcards().get(position).getCreditcardId());
                                        intent1.putExtra("creditcard", cardListBean.getCreditcards().get(position).getIdentityCard());
                                        startActivity(intent1);
                                        break;
                                }
                            }

                        });
                    }
                });
    }
}
